package com.zeng.dao;

import com.zeng.Util.Mybatis;
import com.zeng.pojo.Blog;
import org.junit.Test;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @author zeng
 * @data 2021/07/21 22:56
 */
@SuppressWarnings("all")
public class BlogDemo {
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Test
    public void AddBlog(){
        Blog blog = new Blog();
        blog.setCreatTime(new Date());
        blog.setId("gasdga");
        blog.setAuthor("小王");
        blog.setTitle("spring");
        blog.setViews(200);
        BlogMapper mapper = Mybatis.getSqlSeession().getMapper(BlogMapper.class);
        mapper.InsertBlog(blog);
    }

    @Test
    public void QueryBlog(){
        BlogMapper mapper = Mybatis.getSqlSeession().getMapper(BlogMapper.class);
        HashMap map = new HashMap();
        map.put("author","曾");
        List<Blog> blogs = mapper.queryBlog(map);
        for (Blog blog : blogs) {
            System.out.println(blog);
        }
    }

    @Test
    public void QueryBlog1(){
        BlogMapper mapper = Mybatis.getSqlSeession().getMapper(BlogMapper.class);
        HashMap map = new HashMap();
        map.put("views",290);
        map.put("author","曾");
        List<Blog> blogs = mapper.queryBlog(map);
        for (Blog blog : blogs) {
            System.out.println(blog);
        }
    }

    @Test
    public void UpdateBlog(){
        BlogMapper mapper = Mybatis.getSqlSeession().getMapper(BlogMapper.class);
        HashMap map = new HashMap();
        map.put("title","s");
        map.put("author","小李");
        mapper.UpdateBlogId(map);
    }
}
